import getApiData from '@/services/cpasRequest';

export async function getList(params: {
    temporaryText: string
} & any) {
    const res = await getApiData('myPrject.list', {
        minRN: (params.current - 1) * params.pageSize,
        current: params.current,
        pageSize: params.pageSize,
        searchText: params.keyword,
    });
    return Promise.resolve({
        data: res.data,
        success: true,
    });
}

/**
 * 获取可执行文件信息 
 * @param projectInfo JSON对象
 * @param curUser  JSON对象
 * @returns 
 */
export const getExeInfoObject = (projectInfo: any, curUser: any) => {

    const sjxmcnd: string = projectInfo.sjxmcnd;
    const xmqjStart: string = sjxmcnd && sjxmcnd.substring(0, 10).replaceAll('-', '');
    const xmqjEnd: string = sjxmcnd && sjxmcnd.substring(sjxmcnd.length - 10).replaceAll('-', '');

    const exeInfoObject = {
        //审计作业或查账系统  
        ufcpas4Main: {
            title: '审计作业或查账系统',
            fileName: '{UFCPAS4_PATH}/UFCPAS4.exe',
            params: `UserCode={UserCode} UserPwd={UserPwd} ProjectCode=${projectInfo.sjxmbh} ZcbfID=${projectInfo.ZcbfID}`,
            workDir: '{UFCPAS4_PATH}/SysBPL/'

        },
        //数据采集工具
        dataDumpTool: {
            title: '数据采集工具',
            fileName: '{UFCPAS4_PATH}/数据采集工具/数据采集工具.exe',
            params: '',
            workDir: ''
        },

        //数据转换
        convertData: {
            title: '数据转换系统',
            fileName: '{UFCPAS4_PATH}/DataConvert/P_DataConvert.exe',
            params: ' "' + projectInfo.ZcbfID + '" "' + projectInfo.zcbfName + '" "{SqlInstance}" "' + curUser.usercode + '" "' + xmqjStart + '" "' + xmqjEnd + '" "0" "{SysDataBase}"',
            workDir: ''
        },
        //作业系统空间清理工具
        spaceClear: {
            title: '作业系统空间清理工具',
            fileName: '{UFCPAS4_PATH}/Tools/作业系统空间清理工具.exe',
            params: '',
            workDir: ''
        },
        //SQL批量附加数据库工具
        batAttachDatabase: {
            title: 'SQL批量附加数据库工具',
            fileName: '{UFCPAS4_PATH}/Tools/SQL批量附加数据库工具.exe',
            params: '',
            workDir: ''
        },
    }
    return exeInfoObject;
}
/**
* 获取可执行文件信息(单个) 
* @param projectInfo JSON对象
* @param curUser  JSON对象
* @returns 
*/
export const getExeInfoUrl = (projectInfo: any, curUser: any, key: string) => {
  const aa = 'UserCode=1 UserPwd=1 ProjectCode=FI-2017-00001 ZcbfID=FI-2017-00001 Functions=RIM_110 FunParameters=Data_ID=2017 '
  window.location.href = `cpas://OpenLocalFile/?fileName=C:\\UFCPAS4\\UFCPAS4.exe&params=${aa}`;
}

// 底稿平台 迁移方法 ----------------------------------------------
// Electron相关工具

// 判断是否在electron下运行
export function electron(): boolean {
    return window.electronComponents;
  }
  
  export async function runFun(name: string, props: any): Promise<any> {
    return await window.main[name](props);
  }
  
  /**
   * 打开文件
   * @param filePath // 文件相对路径 路径分隔符使用 / windows也支持。
   * await window.businessService.draftManagerOpenFile({filePath:"201801-AUD-2022-001/201801-AUD-2022-001/底稿/2023_预付账款.xlsx"})
   */
  export function openFile(filePath: string): void { 
    window.businessService.draftManagerOpenFile({filePath});
  }
  
  /**
   * 调用平台打开对话框
   * 没有既可以选文件，又可以选目录的。
   * @param params 有空在细化这个
   * 参考： https://www.electronjs.org/zh/docs/latest/api/dialog
   */
  export async function openDialog(params: any): Promise<any> {
    return await window.electronComponents.openDialog(params);
  }
  
  /**
   * 选择一个目录，没有既可以选文件，又可以选目录的。
   * @returns 
   */
  export function openDirectory(): any {
    return openDialog({
      properties: ['openDirectory']
    });
  }